package net.neptech.service.impl;

import net.neptech.model.information.InforNews;
import net.neptech.model.information.InforTech;
import net.neptech.repository.InforTechRepository;
import net.neptech.service.InforTechService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author 谢辉
 * @Date 2025/8/21 12:03
 * @Description TODO
 **/
@Service
public class InforTechServiceImpl implements InforTechService {

    @Autowired
    InforTechRepository inforTechRepository;
    @Override
    public void addInforTech(InforTech inforTech) {
        inforTech.setPublishTime(new Date());
        inforTechRepository.save(inforTech);
    }

    @Override
    public void deleteInforTech(Long id) {
        //根据id查到文章
        InforTech inforTech = inforTechRepository.findById(id).get();
        //修改文章状态
        inforTech.setStatus(0);
        //保存
        inforTechRepository.save(inforTech);
    }

    @Override
    public List<InforTech> getInforTech() {
        return inforTechRepository.findAllByStatus(1);
    }

    @Override
    public void updateInforTech(InforTech inforTech) {
        inforTech.setPublishTime(new Date());
        inforTechRepository.save(inforTech);
    }

    @Override
    public InforTech getInforTechById(Long id) {
        return inforTechRepository.findById(id).get();
    }
}
